package com.dc.refactoring._3_重新组织数据._13_ReplaceTypeCodeWithStateStrategy.step4;

/**
 * Description: 雇员类
 *
 * @author: gdc
 * @date: 2020/12/4
 * @version 1.0
 */
public class Employee {

    private EmployeeType employeeType;

    // 【9】重新定义方法名称
    int getTypeCode(){
        return employeeType.getTypeCode();
    }

    void setType(int type){
        // 【8】重新定义引用
        employeeType = EmployeeType.newType(type);
    }


    public Employee(int type) {
        setType(type);
    }

    /**
     * 月工资
     */
    private double monthlySalary;
    /**
     * 佣金
     */
    private double commission;
    /**
     * 奖金
     */
    private double bonus;

    /**
     * 通过类型码获取薪资信息
     * @return      薪资信息
     */
    double payAmount(){
        switch (getTypeCode()) {
            case EmployeeType.ENGINEER:
                return monthlySalary;
            case EmployeeType.SALESMAN:
                return monthlySalary + commission;
            case EmployeeType.MANAGER:
                return monthlySalary + bonus;
            default:
                throw new RuntimeException("Incorrect Employee");
        }
    }




}
